<%@ page import="com.genghis.ptas.course.entity.CourseComment" %>
<%@ page import="com.genghis.ptas.course.entity.CourseInfo" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="en" class="no-js">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <title>课程信息</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport"/>
    <meta content="" name="description"/>
    <meta content="" name="author"/>
    <!-- BEGIN GLOBAL MANDATORY STYLES -->
    <%@include file="../../includes/courseInfoStyle.jsp" %>
    <% CourseInfo courseInfo = (CourseInfo) request.getAttribute("course");%>
    <% List<CourseComment> courseCommentList = (List<CourseComment>) request.getAttribute("courseComment");%>
    <%boolean isLogin = (Boolean) request.getAttribute("isLogin");%>
    <%boolean register = (Boolean) request.getAttribute("register");%>
    <%String index = isLogin == true ? "" : " disabled='disabled'";%>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body>

<div class="content">
    <div class="row" style="margin-top: 15px;margin-left: 150px;margin-bottom: 20px;">
        <h1>课件信息:</h1>
        <a onclick="watchCourse('<%=courseInfo.getId()%>')" style="float: left;width:50%">
            <img src="<%=courseInfo.getPhotoUrl()%>" height="330px" width="100%" />
        </a>

        <div style="background:#fff;width:32%;height:250px;margin-top: 50px;margin-right: 150px;float: right">
            <ul style="text-align: left;font-size: 10px">
                <li>
                    <h1 style="font-size: 18px">课件名称：<%=courseInfo.getCourseName()%>
                    </h1>
                </li>
                <li>
                    <h1 style="font-size: 18px">课件类型：<%=courseInfo.getShowCourseType()%>
                    </h1>
                </li>
                <li>
                    <h1 style="font-size: 18px">章节总数：<%=courseInfo.getChapterNum()%>
                    </h1>
                </li>
                <li>
                    <h1 style="font-size: 18px">课件平均得分：<%=courseInfo.getAverageScore()%>
                    </h1>
                </li>
                <li>
                    <h1 style="font-size: 18px">课件质量：<%=courseInfo.getShowQuality()%>
                    </h1>
                </li>
                <li>
                    <h1 style="font-size: 18px">上传人：<%=courseInfo.getUpUserName()%>
                    </h1>
                </li>
            </ul>
            <%if (register) {%>
            <button class="btn btn-small btn-primary" type="button" <%=index%>
                    style="margin-left: 30px" onclick="registerCourse('<%=courseInfo.getId()%>')">
                点击注册
            </button>
            <%} else {%>
            <a class="btn btn-small btn-primary" <%=index%> id="watchLink"
               style="margin-left: 30px" target="_blank"
               href="course/userWatchCourse?id=<%=courseInfo.getId()%>">点击观看</a>
            <%}%>
        </div>
    </div>

    <div>
        <div id="userId" style="margin-left: 150px;margin-bottom: 20px">

        </div>
    </div>

    <div class="col-md-6 col-sm-6" style=" margin-left: 150px">
        <!-- BEGIN PORTLET-->
        <div class="portlet">
            <div class="portlet-title line">
                <div class="caption">
                    <i class="fa fa-comments"></i>评论
                </div>
                <div class="tools">
                    <a href="javascript:void(0);" class="collapse">
                    </a>
                    <a href="javascript:void(0);" class="reload">
                    </a>
                    <a href="javascript:void(0);" class="remove">
                    </a>
                </div>
            </div>
            <div class="portlet-body" id="chats">
                <div class="scroller" style="height: 200px;" data-always-visible="1" data-rail-visible1="1">
                    <ul class="chats">
                        <% for (CourseComment courseComment : courseCommentList) {
                            if (courseComment.getJudgeUser() != 1) {
                        %>
                        <li class="in">
                            <img class="avatar img-responsive" alt=""
                                 src="<%=courseComment.getUserPhotoUrl()==null?"assets/img/avatar1.jpg":courseComment.getUserPhotoUrl()%>"/>

                            <div class="message">
                                <span class="arrow"></span>
                                <a href="javascript:void(0);" class="name">
                                    <%=courseComment.getUserName()%>
                                </a>
                        	<span class="datetime">
                                <%=courseComment.getCommentDate()%>
                        	</span>
                            <span class="body">
                                <%=courseComment.getCommentContent()%>
                            </span>
                            </div>
                        </li>
                        <%} else {%>
                        <li class="out">
                            <img class="avatar img-responsive" alt=""
                                 src="<%=courseComment.getUserPhotoUrl()==null?"assets/img/avatar1.jpg":courseComment.getUserPhotoUrl()%>"/>

                            <div class="message">
                                <span class="arrow"></span>
                                <a href="javascript:void(0);" class="name">
                                    <%=courseComment.getUserName()%>
                                </a>
                            <span class="datetime">
                                <%=courseComment.getCommentDate()%>
                            </span>
                            <span class="body">
                                <%=courseComment.getCommentContent()%>
                            </span>
                            </div>
                        </li>
                        <%
                                }
                            }
                        %>
                    </ul>
                </div>
                <div class="chat-form">
                    <div class="input-cont">
                        <input id="content" class="form-control" type="text" placeholder="评论信息..."/>
                    </div>
                    <div class="btn-cont">
                    <span class="arrow">
                    </span>
                        <a href="javascript:void(0);" onclick="submitComment('<%=courseInfo.getId()%>')" <%=index%>
                           class="btn blue icn-only">
                            <i class="fa fa-check icon-white"></i>
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <!-- END PORTLET-->
    </div>
</div>
<!-- END CONTAINER -->
<!-- BEGIN FOOTER -
<!-- END PAGE LEVEL SCRIPTS -->
<script>
    jQuery(document).ready(function () {
        App.init(); // initlayout and core plugins
        Index.init();
        Index.initJQVMAP(); // init index page's custom scripts
        Index.initCalendar(); // init index page's custom scripts
        Index.initCharts(); // init index page's custom scripts
        Index.initChat();
        Index.initMiniCharts();
        Index.initDashboardDaterange();
        Tasks.initDashboardWidget();
        getUserInfo();
    });

    function registerCourse(courseId) {
        $.ajax({
            url: basePath + "courseRegister/addCourseRegister",
            async: false,
            data: {
                courseId: courseId,
                totalTime: "0000:00:00.00"
            },
            dataType: "json",
            type: "POST",
            success: function (judge) {
                if (judge) {
                    parent.bootbox.alert("注册成功！");
                } else {
                    parent.bootbox.alert("您已注册可以直接观看！");
                }

            },
            error: function () {
                parent.bootbox.alert("注册失败！");
            }
        })
    }

    function submitComment(id) {
        $.ajax({
            url: basePath + "course/courseComment",
            async: false,
            data: {
                courseId: id,
                commentContent: $("#content").val().trim()
            },
            dataType: "json",
            type: "POST",
            success: function () {
            },
            error: doError
        })
    }

    function getUserInfo() {
        $.ajax({
            url: basePath + "courseRegister/courseWhetherRegister",
            async: false,
            data: {
                courseId: "<%=courseInfo.getId()%>"
            },
            dataType: "json",
            type: "POST",
            success: function (judge) {
                if (judge) {
                } else {
                    $.ajax({
                        url: basePath + "courseRegister/getLearnState",
                        data: {
                            courseId: '<%=courseInfo.getId()%>'
                        },
                        dataType: "json",
                        type: "GET",
                        success: function (registerInfo) {
                            $("#userId").append("<h2 style='color: #500000'>我的学习记录:</h2>" +
                                    "<h1 style='font-size: 18px;color: #500000;margin-left: 50px;float: left'>学习状态：<span style='font-size: 15'>" + registerInfo.showState + "</span></h1>" +
                                    "<h1 style='font-size: 18px;color: #500000;margin-left: 450px'>上次观看时间： <span style='font-size: 15'>" + registerInfo.lastTime + "</span></h1>"+
                                    "<br><h1 style='font-size: 18px;color: #500000;margin-left: 50px;float: left'>我的评分：<span style='font-size: 15'>" + registerInfo.score + "</span></h1>" +
                                    "<h1 style='font-size: 18px;color: #500000;margin-left: 450px'>总观看时间： <span style='font-size: 15'>" + registerInfo.totalTime + "</span></h1>");
                        },
                        error: function () {
                            parent.bootbox.alert("您的信息有问题！");
                        }
                    })
                }
            },
            error: function () {
            }
        })
    }

</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>